package Reunion::User::Model::User;

use strict;
use warnings;
use Digest::MD5 qw(md5_hex);

my $USER = {
    'user_id'      => 'user_id',
    'user_name'    => 'user_name',
    'password'     => 'password',
    'user_lang'    => 'user_lang',
    'user_status'  => 'user_status',
    'user_type'    => 'user_type',
    'user_owner'   => 'user_owner',
    'user_group'   => 'user_group',
    'user_company' => 'user_company',
    'create_time'  => 'create_time'
};



sub new {
    my $class = shift;
    my $dbi = shift;
    my $self  = {};
    $self->{'dbi'} = $dbi;
    bless $self, $class;
    return $self;
}

sub login {
    my ($this, $username, $password) = @_;
    $password = md5_hex($password);
    my $selectColumn = [$USER->{'user_id'},$USER->{'user_name'},$USER->{'user_lang'},$USER->{'user_status'},$USER->{'user_type'},$USER->{'user_owner'},$USER->{'user_group'},$USER->{'user_company'}];
    my $where = {$USER->{'user_name'}=>$username, $USER->{'password'}=>$password, $USER->{'user_status'}=>1};
    my $result = $this->{'dbi'}->select($selectColumn, 'table'=>'user', 'where'=>$where);
    return $result;
}

sub getUserList {
    my $this = shift;
    my $selectColumn = [$USER->{'user_id'},$USER->{'user_name'},$USER->{'user_lang'},$USER->{'user_status'},$USER->{'user_type'},$USER->{'user_owner'},$USER->{'user_group'},$USER->{'user_company'}];
    my $where = $USER->{'user_owner'}.' != 0';
    my $result = $this->{'dbi'}->select($selectColumn, 'table'=>'user', 'where'=>$where);
    return $result;
}


1;